package com.xls.app.controller;

import com.xls.app.bean.Category;
import com.xls.app.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    /**
     * @param page 是页面传递过来的参数名称
     * @param rows 是页面传递过过来的参数
     * @return   map集合
     */
    @RequestMapping("/listPage")
    public Map<String,Object>listPage(int page,int rows,String cateName){
        Map<String,Object> map=new HashMap<>();
        //统计分页记录数返回到页面中去，map的键不能随意写，前端表格规定的名称
        map.put("total",categoryService.countCategory(cateName));
        //结果及的map的键也是不能随意写，前端表格规定的名称
        map.put("rows",categoryService.listPageCategory(page,rows,cateName));
        return map;
    }

    @RequestMapping("/saveCategory")
    public  boolean saveCategory(Category category){
        return categoryService.saveCategory(category);
    }

    @RequestMapping("/updateCategory")
    public  boolean updateCategory(Category category){
        return categoryService.updateCategory(category);
    }

    @RequestMapping("/removeBatchCategory")
    public  boolean removeBatchCategory(@RequestParam("cids[]") List<Integer> cids){
        return categoryService.removeBatchCategory(cids);
    }
    @RequestMapping("/listCategory")
    public  List<Category>listCategory(){
        return categoryService.listCategory();
    }
}
